import {
    fetchTempUpgradePlanRecord,
    fetchListTitleChat,
    fetchListMyChatTitle,
    fakeAdminStartChat,
    fakeLikeChat,
    fakeRemoveChatTitle,
    fakeRenameChatTitle,
    fetchAnalysisMyChatTitle,
    fetchAnalysisListTitleChat,
    fakeAnalysisSaveUserAiAnalysisChatTitleWithChat,
    fakeAdminChat,
    fakeAnalysisRenameChatTitle,
    fakeAnalysisRemoveChatTitle,
    fetchChatByAiChatId,
    fetchListCampus,
    fakeSaveCampus,
    fakeRemoveCampus,
    fetchListCampusClassroom,
    fakeSaveCampusClassroom,
    fakeRemoveCampusClassroom,
    fetchListSchedule,
    fakeRemoveSchedule,
    fakeSaveSchedule,
    fetchListSubject,
    fakeSaveSubject,
    fakeRemoveSubject,
    fetchListTeacherTag,
    fakeSaveTeacherTag,
    fakeRemoveTeacherTag,
    fetchListTeacher,
    fetchTeacherDetail,
    fakeSaveTeacher,
    fakeSetRecommended,
    fakeEnableTeacher,
    fakeDisableTeacher,
    fetchListTeacherQaConfig,
    fakeSaveTeacherQaConfig,
    fetchListTeacherSchedule,
    fetchTeacherScheduleDetail,
    fakeSaveTeacherScheduleConfig,
    fetchGetSubjectQaConfig,
    fakeSaveSubjectQaConfig,
    fetchListUserQaAmountPriceConfig,
    fetchUserQaAmountPriceConfigDetail,
    fakeSaveUserQaAmountPriceConfig,
    fakeRemoveUserQaAmountPriceConfig,
    fetchCheckChatFlag,
    fetchListUserQa,
    fetchListLastUserQaRecord,
    fakeChatUserQa,
    fetchUserQaRecord,
    fetchUserHelpQaForAdmin,
    fakeUserQaChangeHandpicked,
    fakeSaveHelpQaAnswer,
    fetchListUserHelpQaAnswerForAdmin,
    fetchUserHelpQaAnswerCommentForAdmin,
    fetchUserHelpQaAnswerByIdForAdmin,
    fakeUserHelpQaChangeHandpicked,
    fakeUserQaChangeTeacher,
    fetchListQaAmountRecord
} from '@/services/AnsweringServices';
import { notification } from 'antd';
const BehaviorEecord = {
    namespace: 'answering',
    state: {
        tempUpgradePlanRecordList: { list: [], total: 0 },
        dateAiChatTitleList: [],
        aiChatData: {},
        teacherList: { list: [], total: 0 },
        teacherScheduleList: {
            list: [], total: 0
        },
        campusClassroomList: [],
        scheduleList: [],
        userQaList: { list: [], total: 0 },
        userHelpQaList: { list: [], total: 0 },
        userHelpQaAnswerList: { list: [], total: 0 },
        userQaAmountRecordList: { list: [], total: 0 },
    },
    effects: {


        * fetchListQaAmountRecord({ payload, callback }, { call, put }) {
            const response = yield call(fetchListQaAmountRecord, payload);
            if (!response) return;
            const { content = {} } = response
            const { userQaAmountRecordList, total } = response.content;
            yield put({
                type: 'save',
                payload: {
                    userQaAmountRecordList: {
                        list: userQaAmountRecordList,
                        total,
                    },
                },
            });
        },
        * fakeUserHelpQaChangeHandpicked({ payload, callback }, { call, put }) {
            const response = yield call(fakeUserHelpQaChangeHandpicked, payload);
            if (!response) return;
            if (!response) return;
            const { content } = response
            notification.success({
                message: '温馨提示',
                description: '设置成功',
            });
            callback && callback(content)
        },
        * fakeUserQaChangeTeacher({ payload, callback }, { call, put }) {
            const response = yield call(fakeUserQaChangeTeacher, payload);
            if (!response) return;
            if (!response) return;
            const { content } = response
            notification.success({
                message: '温馨提示',
                description: '设置成功',
            });
            callback && callback(content)
        },

        * fetchUserHelpQaAnswerByIdForAdmin({ payload, callback }, { call, put }) {
            const response = yield call(fetchUserHelpQaAnswerByIdForAdmin, payload);
            if (!response) return;
            const { content = {} } = response
            const { userHelpQaAnswer } = response.content;
            callback && callback(userHelpQaAnswer)
        },
        * fetchUserHelpQaAnswerCommentForAdmin({ payload, callback }, { call, put }) {
            const response = yield call(fetchUserHelpQaAnswerCommentForAdmin, payload);
            if (!response) return;
            const { content = {} } = response
            const { userHelpQaAnswerCommentList, total } = response.content;
            callback && callback(userHelpQaAnswerCommentList, total)
        },

        * fetchListUserHelpQaAnswerForAdmin({ payload, callback }, { call, put }) {
            const response = yield call(fetchListUserHelpQaAnswerForAdmin, payload);
            if (!response) return;
            const { content = {} } = response
            const { userHelpQaAnswerList, total } = response.content;
            callback && callback(userHelpQaAnswerList, total)
        },
        * fakeUserQaChangeHandpicked({ payload, callback }, { call, put }) {
            const response = yield call(fakeUserQaChangeHandpicked, payload);
            if (!response) return;
            if (!response) return;
            const { content } = response
            notification.success({
                message: '温馨提示',
                description: '设置成功',
            });
            callback && callback(content)
        },
        * fakeSaveHelpQaAnswer({ payload, callback }, { call, put }) {
            const response = yield call(fakeSaveHelpQaAnswer, payload);
            if (!response) return;
            if (!response) return;
            const { content } = response
            notification.success({
                message: '温馨提示',
                description: '回复成功',
            });
            callback && callback(content)
        },

        * fetchUserHelpQaForAdmin({ payload, callback }, { call, put }) {
            const response = yield call(fetchUserHelpQaForAdmin, payload);
            if (!response) return;
            const { content = {} } = response
            const { userHelpQaList, total } = response.content;
            yield put({
                type: 'save',
                payload: {
                    userHelpQaList: {
                        list: userHelpQaList,
                        total,
                    },
                },
            });
            callback && callback(userHelpQaList)
        },

        * fetchListUserQa({ payload, callback }, { call, put }) {
            const response = yield call(fetchListUserQa, payload);
            if (!response) return;
            const { content = {} } = response
            const { userQaList, total } = response.content;
            yield put({
                type: 'save',
                payload: {
                    userQaList: {
                        list: userQaList,
                        total,
                    },
                },
            });
            callback && callback(userQaList)
        },

        * fetchUserQaRecord({ payload, callback }, { call, put }) {
            const response = yield call(fetchUserQaRecord, payload);
            if (!response) return;
            const { content = {} } = response
            const { userQaRecordList } = response.content;
            callback && callback(userQaRecordList)
        },
        * fetchListLastUserQaRecord({ payload, callback }, { call, put }) {
            const response = yield call(fetchListLastUserQaRecord, payload);
            if (!response) return;
            const { content = {} } = response
            const { userQaRecordList } = response.content;
            callback && callback(userQaRecordList)
        },
        * fetchListUserQaAmountPriceConfig({ payload, callback }, { call, put }) {
            const response = yield call(fetchListUserQaAmountPriceConfig, payload);
            if (!response) return;
            const { content = {} } = response
            callback && callback(content)
        },

        * fetchUserQaAmountPriceConfigDetail({ payload, callback }, { call, put }) {
            const response = yield call(fetchUserQaAmountPriceConfigDetail, payload);
            if (!response) return;
            const { content = {} } = response
            callback && callback(content)
        },

        * fakeSaveUserQaAmountPriceConfig({ payload, callback }, { call, put }) {
            const response = yield call(fakeSaveUserQaAmountPriceConfig, payload);
            if (!response) return;
            if (!response) return;
            const { content } = response
            notification.success({
                message: '温馨提示',
                description: '保存成功',
            });
            callback && callback(content)
        },

        * fakeRemoveUserQaAmountPriceConfig({ payload, callback }, { call, put }) {
            const response = yield call(fakeRemoveUserQaAmountPriceConfig, payload);
            if (!response) return;
            if (!response) return;
            const { content } = response
            notification.success({
                message: '温馨提示',
                description: '删除成功',
            });
            callback && callback(content)
        },
        * fakeChatUserQa({ payload, callback }, { call, put }) {
            const response = yield call(fakeChatUserQa, payload);
            if (!response) return;
            if (!response) return;
            const { content } = response
            notification.success({
                message: '温馨提示',
                description: '回复成功',
            });
            callback && callback(content)
        },



        * fetchGetSubjectQaConfig({ payload, callback }, { call, put }) {
            const response = yield call(fetchGetSubjectQaConfig, payload);
            if (!response) return;
            const { content } = response.content;
            callback && callback(response.content)
        },
        * fakeSaveSubjectQaConfig({ payload, callback }, { call, put }) {
            const response = yield call(fakeSaveSubjectQaConfig, payload);
            if (!response) return;
            if (!response) return;
            const { content } = response
            notification.success({
                message: '温馨提示',
                description: '保存成功',
            });
            callback && callback(content)
        },

        * fetchListOfflineQASchedule({ payload, callback }, { call, put }) {
            const response = yield call(fetchListTeacherSchedule, payload);
            if (!response) return;
            const { teacherScheduleList, total } = response.content;
            yield put({
                type: 'save',
                payload: {
                    teacherScheduleList: {
                        list: teacherScheduleList,
                        total,
                    },
                },
            });
            callback && callback(teacherScheduleList)
        },
        * fetchListTeacherSchedule({ payload, callback }, { call, put }) {
            const response = yield call(fetchListTeacherSchedule, payload);
            if (!response) return;
            const { teacherScheduleList, total } = response.content;
            callback && callback(teacherScheduleList)
        },
        * fetchTeacherScheduleDetail({ payload, callback }, { call, put }) {
            const response = yield call(fetchTeacherScheduleDetail, payload);
            if (!response) return;
            if (!response) return;
            const { content } = response
            callback && callback(content)
        },
        * fakeSaveTeacherScheduleConfig({ payload, callback }, { call, put }) {
            const response = yield call(fakeSaveTeacherScheduleConfig, payload);
            if (!response) return;
            if (!response) return;
            const { content } = response
            notification.success({
                message: '温馨提示',
                description: '保存成功',
            });
            callback && callback(content)
        },
        * fetchListTeacher({ payload, callback }, { call, put }) {
            const response = yield call(fetchListTeacher, payload);
            if (!response) return;
            const { teacherList, total } = response.content;
            yield put({
                type: 'save',
                payload: {
                    teacherList: {
                        list: teacherList,
                        total,
                    },
                },
            });
        },
        * fetchTeacherDetail({ payload, callback }, { call, put }) {
            const response = yield call(fetchTeacherDetail, payload);
            if (!response) return;
            if (!response) return;
            const { content } = response
            callback && callback(content)
        },
        * fakeSaveTeacher({ payload, callback }, { call, put }) {
            const response = yield call(fakeSaveTeacher, payload);
            if (!response) return;
            if (!response) return;
            const { content } = response
            notification.success({
                message: '温馨提示',
                description: '保存成功',
            });
            callback && callback(content)
        },
        * fakeSetRecommended({ payload, callback }, { call, put }) {
            const response = yield call(fakeSetRecommended, payload);
            if (!response) return;
            if (!response) return;
            const { content } = response
            notification.success({
                message: '温馨提示',
                description: '置顶成功',
            });
            callback && callback(content)
        },
        * fakeEnableTeacher({ payload, callback }, { call, put }) {
            const response = yield call(fakeEnableTeacher, payload);
            if (!response) return;
            if (!response) return;
            const { content } = response
            notification.success({
                message: '温馨提示',
                description: '启用成功',
            });
            callback && callback(content)
        },
        * fakeDisableTeacher({ payload, callback }, { call, put }) {
            const response = yield call(fakeDisableTeacher, payload);
            if (!response) return;
            if (!response) return;
            const { content } = response
            notification.success({
                message: '温馨提示',
                description: '禁用成功',
            });
            callback && callback(content)
        },
        * fetchListTeacherQaConfig({ payload, callback }, { call, put }) {
            const response = yield call(fetchListTeacherQaConfig, payload);
            if (!response) return;
            if (!response) return;
            const { content } = response
            callback && callback(content)
        },
        * fakeSaveTeacherQaConfig({ payload, callback }, { call, put }) {
            const response = yield call(fakeSaveTeacherQaConfig, payload);
            if (!response) return;
            if (!response) return;
            const { content } = response
            notification.success({
                message: '温馨提示',
                description: '保存成功',
            });
            callback && callback(content)
        },
        * fetchListCampus({ payload, callback }, { call, put }) {
            const response = yield call(fetchListCampus, payload);
            if (!response) return;
            const { campusList, total } = response.content;
            callback && callback(campusList, total)
        },
        * fetchListCampusClassroom({ payload, callback }, { call, put }) {
            const response = yield call(fetchListCampusClassroom, payload);
            if (!response) return;
            const { campusClassroomList, total } = response.content;
            yield put({
                type: 'save',
                payload: {
                    campusClassroomList: campusClassroomList,
                },
            });
            callback && callback(campusClassroomList, total)
        },
        * fetchListSchedule({ payload, callback }, { call, put }) {
            const response = yield call(fetchListSchedule, payload);
            if (!response) return;
            const { scheduleList, total } = response.content;
            yield put({
                type: 'save',
                payload: {
                    scheduleList: scheduleList,
                },
            });
            callback && callback(scheduleList, total)
        },
        * fetchListSubject({ payload, callback }, { call, put }) {
            const response = yield call(fetchListSubject, payload);
            if (!response) return;
            const { subjectList, total } = response.content;
            callback && callback(subjectList, total)
        },
        * fetchListTeacherTag({ payload, callback }, { call, put }) {
            const response = yield call(fetchListTeacherTag, payload);
            if (!response) return;
            const { teacherTagList, total } = response.content;
            callback && callback(teacherTagList, total)
        },
        * fakeSaveTeacherTag({ payload, callback }, { call, put }) {
            const response = yield call(fakeSaveTeacherTag, payload);
            if (!response) return;
            if (!response) return;
            const { content } = response
            notification.success({
                message: '温馨提示',
                description: '保存成功',
            });
            callback && callback(content)
        },
        * fakeRemoveTeacherTag({ payload, callback }, { call, put }) {
            const response = yield call(fakeRemoveTeacherTag, payload);
            if (!response) return;
            if (!response) return;
            const { content } = response
            notification.success({
                message: '温馨提示',
                description: '删除成功',
            });
            callback && callback(content)
        },
        * fakeSaveSubject({ payload, callback }, { call, put }) {
            const response = yield call(fakeSaveSubject, payload);
            if (!response) return;
            if (!response) return;
            const { content } = response
            notification.success({
                message: '温馨提示',
                description: '保存成功',
            });
            callback && callback(content)
        },
        * fakeRemoveSubject({ payload, callback }, { call, put }) {
            const response = yield call(fakeRemoveSubject, payload);
            if (!response) return;
            if (!response) return;
            const { content } = response
            notification.success({
                message: '温馨提示',
                description: '删除成功',
            });
            callback && callback(content)
        },
        * fakeSaveCampus({ payload, callback }, { call, put }) {
            const response = yield call(fakeSaveCampus, payload);
            if (!response) return;
            if (!response) return;
            const { content } = response
            notification.success({
                message: '温馨提示',
                description: '保存成功',
            });
            callback && callback(content)
        },
        * fakeRemoveCampus({ payload, callback }, { call, put }) {
            const response = yield call(fakeRemoveCampus, payload);
            if (!response) return;
            if (!response) return;
            const { content } = response
            notification.success({
                message: '温馨提示',
                description: '删除成功',
            });
            callback && callback(content)
        },
        * fakeSaveCampusClassroom({ payload, callback }, { call, put }) {
            const response = yield call(fakeSaveCampusClassroom, payload);
            if (!response) return;
            if (!response) return;
            const { content } = response
            notification.success({
                message: '温馨提示',
                description: '保存成功',
            });
            callback && callback(content)
        },
        * fakeRemoveCampusClassroom({ payload, callback }, { call, put }) {
            const response = yield call(fakeRemoveCampusClassroom, payload);
            if (!response) return;
            if (!response) return;
            const { content } = response
            notification.success({
                message: '温馨提示',
                description: '删除成功',
            });
            callback && callback(content)
        },
        * fakeSaveSchedule({ payload, callback }, { call, put }) {
            const response = yield call(fakeSaveSchedule, payload);
            if (!response) return;
            if (!response) return;
            const { content } = response
            notification.success({
                message: '温馨提示',
                description: '保存成功',
            });
            callback && callback(content)
        },
        * fakeRemoveSchedule({ payload, callback }, { call, put }) {
            const response = yield call(fakeRemoveSchedule, payload);
            if (!response) return;
            if (!response) return;
            const { content } = response
            notification.success({
                message: '温馨提示',
                description: '删除成功',
            });
            callback && callback(content)
        },
        * fakeAnalysisRenameChatTitle({ payload, callback }, { call, put }) {
            const response = yield call(fakeAnalysisRenameChatTitle, payload);
            if (!response) return;
            if (!response) return;
            const { content } = response
            callback && callback(content)
        },
        * fakeAnalysisRemoveChatTitle({ payload, callback }, { call, put }) {
            const response = yield call(fakeAnalysisRemoveChatTitle, payload);
            if (!response) return;
            if (!response) return;
            const { content } = response
            callback && callback(content)
        },
        * fetchCheckChatFlag({ payload, callback }, { call, put }) {
            const response = yield call(fetchCheckChatFlag, payload);
            if (!response) return;
            if (!response) return;
            const { content } = response
            callback && callback(content)
        },
        * fetchAnalysisMyChatTitle({ payload, callback }, { call, put }) {
            const response = yield call(fetchAnalysisMyChatTitle, payload);
            if (!response) return;
            const { content } = response
            const { dateAiChatTitleList = [] } = response.content;

            callback && callback(dateAiChatTitleList.map(val => {
                let obj = {}
                Object.keys(val).forEach(o => {
                    obj.time = o
                    obj.chatTitleList = val[o]
                })
                return obj
            }))
        },
        * fetchAnalysisListTitleChat({ payload, callback }, { call, put }) {
            const response = yield call(fetchAnalysisListTitleChat, payload);
            if (!response) return;

            const { aiChatList } = response.content;
            callback && callback(aiChatList)
        },
        * fakeAnalysisSaveUserAiAnalysisChatTitleWithChat({ payload, callback }, { call, put }) {
            const response = yield call(fakeAnalysisSaveUserAiAnalysisChatTitleWithChat, payload);
            if (!response) return;
            if (!response) return;
            const { content } = response
            callback && callback(content)
        },
        * fakeAdminChat({ payload, callback }, { call, put }) {
            const response = yield call(fakeAdminChat, payload);
            if (!response) return;
            if (!response) return;
            const { content } = response
            callback && callback(content)
        },
        * fetchTempUpgradePlanRecord({ payload, callback }, { call, put }) {
            const response = yield call(fetchTempUpgradePlanRecord, payload);
            if (!response) return;
            const { tempUpgradePlanRecordList, total } = response.content;
            yield put({
                type: 'save',
                payload: {
                    tempUpgradePlanRecordList: {
                        list: tempUpgradePlanRecordList,
                        total,
                    },
                },
            });
        },
        * fetchListMyChatTitle({ payload, callback }, { call, put }) {
            const response = yield call(fetchListMyChatTitle, payload);
            if (!response) return;
            const { content } = response
            const { dateAiChatTitleList = [] } = response.content;
            yield put({
                type: 'save',
                payload: {
                    aiChatData: {},
                    dateAiChatTitleList: dateAiChatTitleList.map(val => {
                        let obj = {}
                        Object.keys(val).forEach(o => {
                            obj.time = o
                            obj.chatTitleList = val[o]
                        })
                        return obj
                    })
                },
            });
            callback && callback(content)
        },
        * fetchListTitleChat({ payload, callback }, { call, put }) {
            const response = yield call(fetchListTitleChat, payload);
            if (!response) return;

            const { aiChatList } = response.content;
            callback && callback(aiChatList)
        },
        * fakeRemoveChatTitle({ payload, callback }, { call, put }) {
            const response = yield call(fakeRemoveChatTitle, payload);
            if (!response) return;
            if (!response) return;
            const { content } = response
            callback && callback(content)
        },
        * fakeAdminStartChat({ payload, callback }, { call, put }) {
            const response = yield call(fakeAdminStartChat, payload);
            if (!response) return;
            if (!response) return;
            const { content } = response
            callback && callback(content)
        },
        * fakeRenameChatTitle({ payload, callback }, { call, put }) {
            const response = yield call(fakeRenameChatTitle, payload);
            if (!response) return;
            if (!response) return;
            const { content } = response
            callback && callback(content)
        },
        * fakeLikeChat({ payload, callback }, { call, put }) {
            const response = yield call(fakeLikeChat, payload);
            if (!response) return;
            if (!response) return;
            const { content } = response
            callback && callback(content)
        },
        * fetchChatByAiChatId({ payload, callback }, { call, put }) {
            const response = yield call(fetchChatByAiChatId, payload);
            if (!response) return;
            const { content } = response
            callback && callback(content)
        },
    },

    reducers: {
        save(state, { payload }) {
            return {
                ...state,
                ...payload,
            };
        },
    },
};
export default BehaviorEecord;